package com.mimosa.common.message;

import java.util.Set;

import javax.annotation.Resource;

import com.mimosa.common.system.user.TUser;
import com.mimosa.common.system.user.UserService;

/**
 * 邮件服务接口实现类
 * 
 * @author Mr.bai
 * 
 */
// @Service
// @Transactional
public class EmailService {

	@Resource
	private UserService userService;
	@Resource
	private String account;
	@Resource
	private String smtp;
	@Resource
	private String password;
	@Resource
	private String maxLinkNum;

	public void send(TSiteMessage siteMessage) {
		Set<TMessageReceiver> receiver = siteMessage.gettMessageReceiver();
		TUser user = new TUser();
		for (TMessageReceiver mr : receiver) {
			user = userService.getEntity(mr.getReceiverUserId());
		}
		if (user != null && user.getEmail() != null
				&& !user.getEmail().equals("")) {
			SendSetting ss = new SendSetting();
			ss.setAccount(account);
			ss.setMaxLinkNum(maxLinkNum);
			ss.setPassword(password);
			ss.setSmtp(smtp);
			ThreadSendMail smt = new ThreadSendMail(siteMessage, user, ss);
			ThreadPool.run(smt);
		}
	}
}
